package cn.lijiajia3515.cairo.captcha.image;

import cn.hutool.core.util.RandomUtil;
import cn.lijiajia3515.cairo.captcha.CaptchaArgs;
import reactor.util.function.Tuple2;

import java.util.List;

/**
 * 委派 验证码 处理器
 */
public class DelegatingImageCaptchaHandler extends ImageCaptchaHandler {
	private final List<? extends ImageCaptchaHandler> handlers;

	public DelegatingImageCaptchaHandler() {
		this.handlers = List.of(
			CodeImageCaptchaHandler.Singleton.NUM.handler,
			CodeImageCaptchaHandler.Singleton.CHAR.handler,
			CodeImageCaptchaHandler.Singleton.UPPER_CHAR.handler,
			CodeImageCaptchaHandler.Singleton.LOWER_CHAR.handler,
			new ArithmeticImageCaptchaHandler()
		);
	}

	public DelegatingImageCaptchaHandler(List<? extends ImageCaptchaHandler> handlers) {
		this.handlers = handlers;
	}

	@Override
	public ImageCaptcha getCaptcha(CaptchaArgs args) {
		return handlers.get(RandomUtil.randomInt(handlers.size())).getCaptcha(args);
	}

	@Override
	protected Tuple2<String, String> getImageCaptchaStr(CaptchaArgs args) {
		return null;
	}


}
